#include "common.h"

namespace space{

QString startCmd(QString cmd)
{
    QProcess p;
    p.start(cmd);
    p.waitForFinished();
    return p.readAll();
}

bool checkCamera()
{
    return QFile::exists("/dev/video0");
}

int getMemory(const char*path, unsigned long long &availableDisk)
{
    struct statfs data;
    memset(&data, 0, sizeof(data));
    int ret = statfs(path, &data);
    if(ret == 0)
    {
        unsigned long long blocksize = data.f_bsize;	//每个block里包含的字节数
        //unsigned long long totalsize = blocksize * data.f_blocks; 	//总的字节数，f_blocks为block的数目
        /*printf("Total_size = %llu B = %llu KB = %llu MB = %f GB\n",
            totalsize, totalsize>>10, totalsize>>20, totalsize/1024.0/1024/1024);*/

        //freeDisk = data.f_bfree * blocksize;	//剩余空间的大小
        availableDisk = data.f_bavail * blocksize; 	//可用空间大小
#if 0
        log_debug() << "available : " << availableDisk << "B "
                      << "available : " << (availableDisk>>10) << "KB "
                      << "available : " << (availableDisk>>20) << "MB "
                      << (availableDisk>>30) <<  "G";
#endif
    }
    return ret;
}


};
